package com.whz.mutithread;

import lombok.extern.slf4j.Slf4j;

import java.util.HashSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * @Author: sinosoft
 * @Description:
 * @Date: Create in 15:48 2021/5/25
 * @Modified By:
 */
@Slf4j
public class MainTest {
    private static final ConcurrentMap<String, String> map =
            new ConcurrentHashMap<>();
    public static String intern(String s) {
        String previousValue = map.putIfAbsent(s, s);
        return previousValue == null ? s : previousValue;
    }
    public static void main(String[] args) {
//        String name = intern("whz");
//        log.info("name: {}", name);
        String whz = "whz";
        log.info("whz.hashCode() : {}", whz.hashCode());
        log.info("whz.hashCode() : {}", whz.intern().hashCode());
//        ObservableSet<Integer> set =
//                new ObservableSet<>(new HashSet<>());
//        set.addObserver((s, e) -> System.out.println(e));
//        for (int i = 0; i < 100; i++) {
//            set.add(i);
//        }
//        set.addObserver(new SetObserver<Integer>() {
//             @Override
//            public void added(ObservableSet<Integer> set, Integer e) {
//                log.info("元素: {}", e);
//                if(e == 23) {
//                    set.removeObserver(this);
//                }
//            }
//        });
//        for (int i = 0; i < 100; i++) {
//            set.add(i);
//        }

    }
}
